package com.netintech.core.config;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Objects;

/**
 * 判断是否使用webscoket容器，如果使用的是生产环境且是war包的方式不装配bean，
 * 使用方式@Conditional(WarAndJarWebscoketAutoWired.class)
 * 返回true装配,返回false不装配
 */
public class WarAndJarWebscoketAutoWired implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment env = context.getEnvironment();
        String packageStyle = env.getProperty("package.style");
        String active = env.getProperty("spring.profiles.active");
        return (Objects.equals("jar", packageStyle));
    }
}